<!-- 搜索项目 -->
<template>
  <h-select-input-popup
    ref="hSelectInputPopup"
    v-model="val"
    v-bind="$attrs"
    v-on="$listeners"
    :params="queryParams"
    :keywords.sync="keywords"
    :getList="getList"
    @getDetail="getDetail"
		searchPlaceholder="请输入付款金额"
		:use-search="false"
		:isMulti="muitFlag"
    @change="$emit('change', $event)"
  >
    <template v-slot:default="{ item }">
      <view class="project-item">
        <view class="option">
          <view class="lf">合同款项</view>
          <view class="rl">{{ item.contractPayment_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">付款比例</view>
          <view class="rl">{{ item.ratioPayment }}%</view>
        </view>
        <view class="option">
          <view class="lf">付款金额（元）</view>
          <view class="rl">{{ item.paymentAmount }}</view>
        </view>
        <view class="option">
          <view class="lf">累计付款金额（元）</view>
          <view class="rl">{{ item.paymentTotalAmount }}</view>
        </view>
        <view class="option">
          <view class="lf">备注</view>
          <view class="rl">{{ item.remark }}</view>
        </view>
      </view>
    </template>
  </h-select-input-popup>
</template>

<script>
import { purchaseContractPayment } from '@/api/finance/ErpFinanceRepaymentSlipForm'
import http from '@/utils/request'
export default {
  name: 'HSelectOilCardInputPopup',
  data() {
    return {
      getList: purchaseContractPayment,
      params: {
        column: 'createTime',
        order: 'desc',
        pageNo: 1,
        pageSize: 10,
      },
      keywords: '',
    }
  },
  model: {
    prop: 'value',
    event: 'input',
  },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
    showName: {
      type: [String, Number],
      default: null,
    },
    billId: {
      type: [String, Number],
      default: null,
    },
    sysOrgCode: {
      type: [String, Number],
      default: null,
    },
    muitFlag: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    val: {
      get() {
        return this.value
      },
      set() {
        this.$emit('input', this.value)
      },
    },
    queryParams() {
      const params = {
        ...this.params,
      }
      if (this.keywords) {
        params.paymentAmount = this.keywords
      }
      params.billId = this.billId
      params.sysOrgCode = '';
      params.checkStatus = 2; //审核成功
      return params
    },
  },
  methods: {
    // 获取详情
		getDetail(value) {
			if (this.muitFlag) {
			  http.get('/api/erp/purchase/contract/erpPurchaseContractPayment/queryByIds', { ids: value }).then((res) => {
			    if (res.success) {
			      const contractName = res.result.map(i => i.contractPayment_dictText).join(',')
			      this.$refs.hSelectInputPopup.title = contractName
			      this.$emit('select', {
			        data: res.result,
			        id: value,
			      })
			    }
			  })
			} else {
				http.get('/api/erp/purchase/contract/erpPurchaseContractPayment/queryById',{ id: value }).then((res) => {
				  if (res.success) {
				    this.$refs.hSelectInputPopup.title = res.result.contractPayment_dictText
				    this.$emit('select', {
				      data: res.result,
				      id: value,
				    })
				  }
				})
			}
		},
  },
}
</script>

<style lang="scss" scoped>
// 按钮
.btn {
  position: fixed;
  bottom: 20rpx;
  width: 95%;
}
</style>
